package com.app.action;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

/**
 * Action的抽象基类,主要定义了对Preparable,ModelDriven接口的使用,以及CRUD函数的命名.
 * 
 * @author Administrator
 * 
 * @param <T> BaseActionSupport所管理的对象类型.
 * 
 */
@SuppressWarnings("serial")
public abstract class BaseActionSupport<T> extends ActionSupport implements ModelDriven<T>, Preparable {
	protected final Logger logger = LoggerFactory.getLogger(getClass());
	
	protected Integer id;
	
	/**
	 * 重写input()方法，返回SUCCESS.
	 */
	public String input() throws Exception{
		return SUCCESS;
	}

	/**
	 * 显示Entity列表.
	 * 
	 * @return
	 * @throws Exception
	 */
	public String list() throws Exception{
		return SUCCESS;
	}

	/**
	 * 新增或修改Entity.
	 * 
	 * @return
	 * @throws Exception
	 */
	public abstract String saveOrUpdate() throws Exception;

	/**
	 * 删除Entity.
	 * 
	 * @return
	 * @throws Exception
	 */
	public String delete() throws Exception{
		return SUCCESS;
	}

	/**
	 * 在saveOrUpdate()前执行二次绑定.
	 * 
	 * @throws Exception
	 */
	public void prepareSaveOrUpdate() throws Exception {
		prepareModel();
	}

	/**
	 * 在input()前执行二次绑定.
	 * 
	 * @throws Exception
	 */
	public void prepareInput() throws Exception {
		prepareModel();
	}

	/**
	 * 实现空的prepare()函数,屏蔽所有Action函数公共的二次绑定.
	 */
	public void prepare() throws Exception {
	}

	/**
	 * 等同于prepare()的内部函数,供prepareMethodName()函数调用.
	 */
	protected abstract void prepareModel() throws Exception;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}
	
}
